package com.primary.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.primary.controller.request.DonorinfoRequest;
import com.primary.entity.Donorinfo;
import com.primary.mappers.DonorinfoMapper;
import com.primary.service.DonorinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service("DonorinfoService")
public class DonorinfoServiceImpl implements DonorinfoService {

    @Autowired
    DonorinfoMapper donorinfoMapper;

    /**
     * 用于分页显示献血者信息
     *
     * @param donorinfoRequest
     */
    @Override
    public PageInfo<Map<String, Object>> queryByPage(DonorinfoRequest donorinfoRequest) {
        PageHelper.startPage(donorinfoRequest.getPageNum(), donorinfoRequest.getPageSize());
        return new PageInfo<>(donorinfoMapper.listByPage(donorinfoRequest));
    }

    /**
     * 插入一条数据
     *
     * @param donorinfo
     * @return
     */
    @Override
    public int insertOne(Donorinfo donorinfo) {
        return donorinfoMapper.insertOne(donorinfo);
    }

    /**
     * 更新一条信息
     *
     * @param donorinfo
     * @return
     */
    @Override
    public int updateOneById(Donorinfo donorinfo) {
        return donorinfoMapper.updateOneById(donorinfo) != 0 ? 1 : 0;
    }

    /**
     * 删除一条记录
     *
     * @param id
     * @return
     */
    @Override
    public boolean deleteById(Integer id) {
        return donorinfoMapper.deleteById(id) > 0;
    }

    @Override
    public Donorinfo queryDonerByDonors(Donorinfo donorinfo) {
        return donorinfoMapper.queryDonerByDonors(donorinfo);
    }
}
